
$(function () {

  /*  $.ajax({
        url:ROOT_PATH + '/occupationalHealth/phyData/selectAnalysis.shtml',//提交地址
        data:{parentId : 0},//将表单数据序列化
        type:"POST",
        dataType:"json",
        success:function(result){
           debugger;
        }
    });*/



    $('#facilityTb').datagrid({
        rownumbers: true,//显示行号
        striped: true,
        fit: true,
        singleSelect: true,
        sortOrder: true,
        fitColumns: true,
        toolbar: '#toolbar',
        url: ROOT_PATH + '/occupationalHealth/facility/selectAnalysis.shtml',
        columns: [[
            {field: 'com', title: '单位', width: 100, sortable: true,formatter: function (value, row, index) {
                return "总计";
            }},
            {field: 'num1', title: '防护设施数量', width: 100},
            {field: 'num2', title: '完好防护设施数量', width: 100},
            {field: 'num3', title: '停用防护设施数量', width: 100},
            {field: 'aa', title: '完好率', width: 100,formatter: function (value, row, index) {
                var aValue=((row.num2*1)/(row.num1*1)*100).toFixed(2);
                return aValue+"%";
            }}
        ]]
    });
    /**
     * 高级查询
     */
    $('#btn_advanced_search').on("click", function () {
        $('#queryForm2').toggle();
        $('#facilityTb').datagrid('resize');
    });
    $('#btn_clear').on("click", function () {
        $('#queryForm1').form('reset');
        $('#queryForm2').form('reset');
    });
    var code=CONSTANT.DictionaryTypeDefConstants.OHE_FACILITY_TYPE;
    queryComboData(code,'#facilitieTypeQuery');
    queryDepartmentTree();
   
});

function queryDepartmentTree(){
    $.ajax({
        url:ROOT_PATH + '/permission/department/getDepartmentTree.shtml',//提交地址
        data:{parentId : 0},//将表单数据序列化
        type:"POST",
        dataType:"json",
        success:function(result){
            deptCom('searchAddDept',result);
        }
    });
}
function deptCom(id,result) {
    var deptId='#'+id;
    $(deptId).combotree(
        {
            data:result,
            require:true,
            loadFilter:function(data){
                var newData = new Array();
                newData.push({id:"",text:'请选择'});
                newData.push(data[0]);
                return newData;
            }
        }
    );
}


function queryComboData(code,id) {

    var EMPTY_OPTION = {
        id: '',
        text: '请选择'
    };
    $.ajax({
        type: 'post',
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml',
        data: {code: code},
        dataType: "json",
        success: function (result) {
            $(id).combobox({
                loadFilter: function (data) {
                    data.unshift(EMPTY_OPTION);
                    return data;
                },
                data: result,
                valueField: 'id',
                textField: 'text',
                editable: false,
                panelHeight: '200',
                onSelect: function (record) {
                }
            });
        }
    });
}
/**
 * 重新加载表格
 */
function reLoadData() {
    $('#facilityTb').datagrid('clearSelections');
    var queryParams1 = $('#queryForm1').serializeJson();
    var queryParams2 = $('#queryForm2').serializeJson();
    var queryParams = $.extend(queryParams1,queryParams2);
    $('#facilityTb').datagrid('options').queryParams = queryParams;
    $("#facilityTb").datagrid('reload', ROOT_PATH + '/occupationalHealth/facility/selectAnalysis.shtml');
}
